package com.bw.kotlindemo.kotlin.model

import com.bw.kotlindemo.java.model.net.ApiService
import com.bw.kotlindemo.java.model.net.HeadInterceptor
import com.bw.kotlindemo.kotlin.model.net.KApiService
import com.bw.kotlindemo.kotlin.model.net.KHeadInterceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**
 * desc:网络Retrofit工具类
 * create by xushaodong on 2023/4/5
 */
class KRetrofitManager {
    val baseUrl = "http://mobile.bwstudent.com/"
//    val baseUrl = "http://10.59.9.24/"
    var apiService: KApiService
    companion object {
        val instance by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            KRetrofitManager()
        }
    }

    constructor(){
        val okHttpClient = OkHttpClient.Builder()
            .addInterceptor(KHeadInterceptor())
            .readTimeout(5000, TimeUnit.SECONDS)
            .writeTimeout(5000, TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .build()

        val retrofit = Retrofit.Builder()
            .baseUrl(baseUrl)
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build()

        apiService = retrofit.create(KApiService::class.java)

    }




}